{% extends "base.html" %}

{% block title %}注册 - SteHub{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8 col-lg-6">
        <div class="card">
            <div class="card-header">
                <h3 class="text-center mb-0"><i class="fas fa-user-plus me-2"></i>用户注册</h3>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ url_for('auth.register') }}">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="username" class="form-label">用户名</label>
                                <input type="text" class="form-control" id="username" name="username" 
                                       value="{{ request.form.username if request.form }}" required
                                       placeholder="3-20位字母、数字、下划线"
                                       pattern="[a-zA-Z0-9_-]{3,20}">
                                <div class="form-text">用户名将用于登录和显示</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="email" class="form-label">邮箱地址</label>
                                <input type="email" class="form-control" id="email" name="email" 
                                       value="{{ request.form.email if request.form }}" required
                                       placeholder="请输入有效的邮箱地址">
                                <div class="form-text">用于密码重置和重要通知</div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="password" class="form-label">密码</label>
                                <input type="password" class="form-control" id="password" name="password" 
                                       required placeholder="至少8位字符"
                                       minlength="8">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="confirm_password" class="form-label">确认密码</label>
                                <input type="password" class="form-control" id="confirm_password" 
                                       name="confirm_password" required placeholder="再次输入密码">
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <div class="form-check">
                            <input type="checkbox" class="form-check-input" id="agree_terms" name="agree_terms" required>
                            <label class="form-check-label" for="agree_terms">
                                我同意 <a href="{{ url_for('main.terms') }}" target="_blank">服务条款</a> 
                                和 <a href="{{ url_for('main.privacy') }}" target="_blank">隐私政策</a>
                            </label>
                        </div>
                    </div>
                    
                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-primary btn-lg">
                            <i class="fas fa-user-plus me-2"></i>注册账户
                        </button>
                    </div>
                </form>
                
                <div class="text-center mt-4">
                    <p class="mb-0">
                        已有账户？
                        <a href="{{ url_for('auth.login') }}" class="text-decoration-none">立即登录</a>
                    </p>
                </div>
            </div>
        </div>

        <!-- 注册优势 -->
        <div class="card mt-4">
            <div class="card-body">
                <h6 class="text-center mb-3">加入 SteHub，享受以下功能：</h6>
                <div class="row text-center">
                    <div class="col-4">
                        <i class="fas fa-comments fa-2x text-primary mb-2"></i>
                        <p class="small mb-0">论坛交流</p>
                    </div>
                    <div class="col-4">
                        <i class="fas fa-comment-dots fa-2x text-success mb-2"></i>
                        <p class="small mb-0">实时聊天</p>
                    </div>
                    <div class="col-4">
                        <i class="fas fa-share-alt fa-2x text-info mb-2"></i>
                        <p class="small mb-0">资源共享</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    const password = document.getElementById('password');
    const confirmPassword = document.getElementById('confirm_password');
    
    function validatePassword() {
        if (password.value !== confirmPassword.value) {
            confirmPassword.setCustomValidity('密码不一致');
        } else {
            confirmPassword.setCustomValidity('');
        }
    }
    
    password.addEventListener('change', validatePassword);
    confirmPassword.addEventListener('keyup', validatePassword);
});
</script>
{% endblock %}